#include "SDL2/SDL.h"
#include <iostream>
#include "SDL2/SDL_ttf.h"
#include "SDL2/SDL_image.h"
#include <stdexcept>
#include <string>
#include "SDLTool.h"
#include "Timer.h"
#include "SDLWindow.h"
#include "SDLActor.h"
#include "SDLParticle.h"

//定义屏幕尺寸常量
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
//每秒的帧数
const int FRAMES_PER_SECOND = 60;
using namespace std;

int main(int argc, char** argv)
{
    (void)argc;
    (void)argv;
    SDL_Event event;
    int tmp;

    SDLWindow *sdlwindow = new SDLWindow("sdlwindow", 640, 480);
    sdlwindow->setWindowPos(20,20);
    sdlwindow->setBackground("../assert/background.png");
    SDLActor sdlActor;
    //getSDLRender这里加载资源时，使用的render是很重要的， 因为加载到哪一个环境，就只能在哪一个里面使用
    sdlActor.setBackground(sdlwindow->getSDLRender(), "../assert/actor.png");
    sdlwindow->addSDLBase((SDLBase*)&sdlActor);
    

    SDLWindow *sdlwindow1 = new SDLWindow("sdlwindow1", 640, 480);
    sdlwindow1->setWindowPos(20,600);
    sdlwindow1->setBackground("../assert/background.bmp");

    SDLParticle SDLParticle[60];
    for( int i = 0; i < 60; i++ )
    {
        SDLParticle[i].setBackground(sdlwindow1->getSDLRender(), "../assert/particle.png");
        SDLParticle[i].setPos( rand() % 640, rand() % 480 );
        tmp = rand() % 10;
        SDLParticle[i].setSize( tmp, tmp );
        SDLParticle[i].SetAnimPreSecond( rand() % 4 + 1 );
        sdlwindow1->addSDLBase((SDLBase*)&SDLParticle[i]);
    }

    while(sdlwindow->isExit == false)
    {
        sdlwindow->show();
        sdlwindow1->show();
        while( SDL_PollEvent( &event ) )
        {
            sdlwindow->handleEvent(event);
            sdlwindow1->handleEvent(event);
        }
    }

    SDL_Quit();
    return 0;
}